//根据返回的类型判断是跳转到本程序页面还是 h5链接
function pagebyTypeJump(type, url, pageId) {
	// 链接类型:site=网页,miniapp=小程序
	if (url) {
		if (type == 'site') {
			uni.navigateTo({
				url: '/pages/webView?pageurl=' + encodeURIComponent(url)
			})
		}
		if (type == 'miniapp') {
			uni.navigateTo({
				url: url
			})
		}
	}
	// console.log('测试', type, url)
}

function isValidPhoneNumber(phoneNumber) {
	const regex = /^1[3-9]\d{9}$/;
	return regex.test(phoneNumber);
}

function filedownload(file) {
	uni.showLoading({
		title: '下载中'
	});
	let that = this
	uni.downloadFile({
		url: file, //这里配置下载的路径
		success: (data) => {
			if (data.statusCode === 200) {
				const fileManager = uni.getFileSystemManager();
				fileManager.saveFile({ //文件保存到本地
					tempFilePath: data.tempFilePath, //临时路径
					success: function(res) {
						uni.showToast({
							icon: 'none',
							mask: true,
							title: '文件已保存!',
							duration: 3000,
						});
						uni.openDocument({
							fileType: 'pdf',
							filePath: res.savedFilePath,
							showMenu: true,
							success: function(res) {}
						});
						uni.hideLoading()
					}
				});
			}
		}
	});
}
// 企业微信客服
function openEnterpriseKF(file) {
	// #ifdef  MP-WEIXIN  
	wx.openCustomerServiceChat({
		extInfo: {
			url: 'https://work.weixin.qq.com/kfid/kfc6c8447b2e4daec3d' //客服地址链接
		},
		corpId: 'ww632540a0ddff1564', //必须和你小程序上的一致
		success(res) {
			console.log(res, '企业微信客服')
		},
		fail(res) {
			console.log(res, '企业微信客服')
		},
	})
	// #endif
}
// 根据subjectcateId跳转到不同的页面查看结果
function diffResultById(subjectcateId,recordId){
	if(subjectcateId ==3){
		uni.navigateTo({
			url: '/pages/onlineTest/lookResultInfo?record_id='+recordId
		});
	}
	if(subjectcateId ==1){
		uni.navigateTo({
			url: '/pages/onlineTest/lookResultInfoDetail?record_id='+recordId
		});
	}
	if(subjectcateId ==5){
		uni.navigateTo({
			url: '/pages/onlineTest/lookResultInfoother?record_id='+recordId
		});
	}
}
export {
	pagebyTypeJump,
	isValidPhoneNumber,
	filedownload,
	openEnterpriseKF,
	diffResultById
}